<template>
	<view class="content">
		<view class="input-p">
			<view class=""><text>企业名称</text><input type="text" v-model="name" placeholder="请输入"/></view>
			<view class=""><text>企业地址</text><input type="text" v-model="address" placeholder="请输入"/></view>
			<view class=""><text>电话</text><input type="text" v-model="tel" placeholder="请输入"/></view>
			<view class=""><text>法人</text><input type="text" v-model="faren" placeholder="请输入"/></view>
			<view class="kp" @click="showbox">
				<text>开票信息</text>
				<input type="text" value="" placeholder="请选择" disabled="true" />
				<image src="/static/icon_more.png" mode=""></image>
			</view>
			<view v-if="show"><text>纳税人识别号</text><input type="text" v-model="kp_num" placeholder="请输入"/></view>
			<view v-if="show"><text>开票信息中的地址</text><input type="text" v-model="address" placeholder="请输入"/></view>
			<view v-if="show"><text>开票信息中的电话</text><input type="text" v-model="tel" placeholder="请输入"/></view>
			<view v-if="show"><text>开户行</text><input type="text" v-model="kp_bank" placeholder="请输入"/></view>
			<view v-if="show"><text>银行卡号</text><input type="text" v-model="kp_card_num" placeholder="请输入"/></view>
		</view>
		<view class="card">
			<view class="card_title">营业执照上传</view>
			<view class="card_content" @click="chooseImg">
				<image :src="tempFilePaths" mode=""></image>
			</view>
		</view>
		<button class="login" @click="editCompanyInfo">注册</button>
	</view>
</template>

<script>
	import API from '../../common/api.js';
	export default {
		data() {
			return {
				show:false,
				userid:uni.getStorageSync("userid"),//用户id(登录时返回的)
				name:'',//企业名称
				address:'',//企业地址
				tel:'',//企业电话
				faren:'',//法人
				kp_num:'',//纳税人识别号
				kp_address:'',//开票信息中的地址
				kp_tel:'',//开票信息中的电话
				kp_bank:'',//开户行
				kp_card_num:'',//银行卡号
				zhizhao_url:'',//营业执照照片路径
				tempFilePaths:'/static/btn_up.png',
				baseURL:API.baseURL,
			}
		},
		onLoad(){
			this.findCompanyInfo();
			// #ifdef APP-PLUS
			/* 隐藏凸起图标 */
			var icon = plus.nativeObj.View.getViewById("icon");
			setTimeout(function() {
				if(icon){icon.hide();}
			}, 100);
			// #endif
		},
		methods: {
			findCompanyInfo(){//查询企业信息
				var _this = this;
				uni.request({
					url:API.findCompanyInfo,
					data:{
						type:2,
						userId:_this.userid,
					},
					method:"POST",
					header:API.get_head(),
					success: (res) => {
						if(res.data==null||!res.data.faren||!res.data.faren||!res.data.tel||!res.data.address){
							
						}else{
							_this.name=res.data.fullname;//企业名称
							_this.address=res.data.address;//企业地址
							_this.tel=res.data.tel;//企业电话
							_this.faren=res.data.faren;//法人
							_this.kp_num=res.data.kp_num;//纳税人识别号
							_this.kp_address=res.data.kp_address;//开票信息中的地址
							_this.kp_tel=res.data.kp_tel;//开票信息中的电话
							_this.kp_bank=res.data.kp_bank;//开户行
							_this.kp_card_num=res.data.kp_card_num;//银行卡号
							_this.zhizhao_url=res.data.zhizhao_url;//营业执照照片路径
							_this.tempFilePaths=_this.baseURL+res.data.address;
						}
						
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					}
				})
			},
			chooseImg(){
				var _this = this;
				uni.chooseImage({
					sourceType: ["camera", "album"],
					sizeType: "compressed",
					count: 1,
					success: (res) => {
						_this.tempFilePaths = res.tempFilePaths;
						
						uni.uploadFile({
							url: API.upload,
							headers:{
								"content-type":"application/x-www-form-urlencoded",
							},
							name: 'file',
							filePath: res.tempFilePaths[0],
							success: function(res) {
								var data = JSON.parse(res.data)
								if(data.msg=="success"){
									_this.zhizhao_url = data.fileName;
								}
							},
							fail: function(res) {
								uni.showToast({
									title:"上传失败",
									icon:'none'
								})
								
							}
						});
					}
				});
			},
			editCompanyInfo(){
				var _this = this;
				if(this.name&&this.address&&this.tel&&this.faren){
					uni.request({
						url:API.editCompanyInfo,
						data:{
							userid:_this.userid,
							name:_this.name,
							address:_this.address,
							tel:_this.tel,
							faren:_this.faren,
							
							kp_num:_this.kp_num,
							
							// kp_address:_this.kp_address,
							// kp_tel:_this.kp_tel,
							kp_address:_this.address,
							kp_tel:_this.tel,
							
							kp_bank:_this.kp_bank,
							kp_card_num:_this.kp_card_num,
							zhizhao_url:_this.zhizhao_url,
						},
						method:"POST",
						header:API.get_head(),
						success: (res) => {
							if(res.data.success){
								uni.switchTab({
									// url:'/pages/measure/Akeymeasure'
									url:'/pages/newpages/home'
								})
							}
							uni.showToast({
								title:res.data.message,
								icon:"none"
							})
						},
						fail: () => {
							uni.showToast({
								title:"加载失败",
								icon:'none'
							})
						}
					})
				}else{
					uni.showToast({
						title:"请完整填写",
						icon:"none"
					})
				}
			},
			gopage(url){
				uni.navigateTo({
					url:url
				})
			},
			showbox(){
				this.show = !this.show
			}
		}
	}
	
</script>

<style>
	page{
		min-height:100%;
		background:#f7f7f7;
	}
	.content{
		
	}
	.input-p>view{
		display:flex;
		font-size:30upx;
		border-bottom:1px solid #e5e5e5;
		padding:45upx 25upx;
		background:#FFFFFF;
		font-size:32upx;
	}
	.input-p>view:last-child{
		border-bottom:none;
	}
	.input-p>view>text{
		display:block;
		width:305upx;
		line-height:55upx;
		color:#333333;
	}
	.input-p>view>input{
		width:395upx;
		vertical-align: middle;
		font-weight:normal;
	}
	.input-p>.kp>input{
		width:355upx;
		vertical-align: middle;
	}
	.input-p>.kp>image{
		width:40upx;
		height:40upx;
		margin-top: 8upx;
	}
	.card{
		margin-top:20upx;
		background:#FFFFFF;
		color:#333333;
	}
	.card .card_title{
		border-bottom:1upx solid #e9e9e9;
		font-size:32upx;
		padding:40upx 25upx;
	}
	.card .card_content{
		padding: 23upx 25upx;
	}
	.card .card_content>image{
		width:327upx;
		height:245upx;
	}
	.login{
		width:630upx;
		height:88upx;
		background:#067aee;
		color:#fff;
		margin:100upx auto 88upx;
		font-size:34upx;
	}
</style>
